package com.calwen.xsmarthome.controller;

import com.calwen.xsmarthome.bo.DeviceProperty;
import com.calwen.xsmarthome.service.MjService;
import com.calwen.xsmarthome.util.ResultUtil;
import com.calwen.xsmarthome.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/debug")
public class Debugcontroller {
    @Autowired
    MjService mjService;

    @GetMapping("/home/devices/list")
    public ResultVO<Object> getHomeDeviceList(Map<String, Object> map) {
        return ResultUtil.success(mjService.getHomeDeviceList(map));
    }

    @PostMapping("/set/property")
    public ResultVO<Boolean> setProperty(@RequestBody Map<String, Object> map) {
        boolean b = mjService.setProperty(null, (List<DeviceProperty>) map.get("params"));
        return ResultUtil.autoDo(b);
    }

    @PostMapping("/get/property")
    public ResultVO<Object> getProperty(@RequestBody Map<String, Object> map) {
        return ResultUtil.success(mjService.getProperty(map));
    }

    @PostMapping("/action")
    public ResultVO<Boolean> doAction(@RequestBody Map<String, Object> map) {
        boolean b = mjService.doAction(map);
        return ResultUtil.autoDo(b);
    }

}
